//
//  MostDetailViewController.m
//  XDCommonApp
//
//  Created by wanglong8889@126.com on 14-3-11.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "MostDetailViewController.h"
#import "XDTools.h"
#import "XDHeader.h"
#import "CommentViewController.h"
#import "UMSocial.h"
#import "UIImageView+WebCache.h"
#import "DetailforArtistVC.h"
#import "LoginViewController.h"

#import "MU_bigImagesViewController.h"
#import "MU_picBlock.h"
#import "CommentCell.h"

#define dHeightForHeader 0
#define dHeightCell  110

@interface MostDetailViewController ()
{
    BOOL isHideLine;
    BOOL isFav;
    BOOL firstFav;
    
    NSString *author;//作者
    NSString *beCommentTime;//评论次数
    NSString *beScanTime;//浏览
    NSString *beStoreTime;//收藏
    NSMutableArray  *commentList;//评论列表
    NSString *recentlySales;//
    NSString *workBigImageUrl;//大图
    NSString *workCategory;//分类
    NSString *workDate;//日期
    NSString *workDescription;//描述
    NSString *workName;//名称
    NSString *workRecord;//录音
    NSString *workSize;//大小
    NSString *workSmallImageUrl;//缩略图
    NSString *signGallery;
    NSString *artistId;
    
    NSString *recordURL;// 录音
    
    UIView * lineView;
    UIView *hlineView;
    UIImageView * favIV;
    UIView * hlineView2;
    UIView * lineView2;
    UIImageView *commIV;
    UILabel *commLb;
    UIButton *toCommitCommBtn;
    UILabel *wordsLabel;
    
    
    NSString *UID_STR;
}
@end

@implementation MostDetailViewController
@synthesize workID;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.titleLabel.text = @"作品详情";
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.font = [UIFont systemFontOfSize:15.0];
    commentList = [NSMutableArray arrayWithCapacity:4];
    
//    isFav = NO;
    [self isFavorite];
    
//    [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector (mytest:) name:@"postData" object:nil];
    [self initViews];
    [self getXmlData];
    [self getArtistRecord];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
//    [self getXmlData];
    
//    [_detailActTableView reloadData];
    
}
- (void)mytest:(NSNotification*)sender// 返回时候刷新数据
{

//    [self getXmlData];

}
-(void)initViews{
    scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, self.contentView.frame.size.height)];
    float heightSize = 0.f;
    if (iPhone5) {
        heightSize = 568;//740;
    }else{
        heightSize = 480;//840;
    }
    isHideLine = YES;
    
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(564/2.0f, 20/2,46/2 , 46/2);
    [rightBtn setImage:[UIImage imageNamed:@"hotPoint_data"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationBarView addSubview:rightBtn];
    
    popupview = [[XDPopUpView alloc] init];
    
    
    scrollview.contentSize = CGSizeMake(320, heightSize);
    headView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 258)];
    headView.image = [UIImage imageNamed:@"placehold_image"];
    headView.backgroundColor = UIColorFromRGB(0xdbdada);
    headView.userInteractionEnabled = YES;
    headView.contentMode = UIViewContentModeScaleAspectFit;
    // 手势
    UITapGestureRecognizer *singleTap =
    
    [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(whenClickImage)];
    
    [headView addGestureRecognizer:singleTap];
    
    [scrollview addSubview:headView];
    [self.contentView addSubview:scrollview];
    titLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, headView.frame.size.height+headView.frame.origin.y+10, 220, 18)];
    titLabel.font = [UIFont systemFontOfSize:14.0];
    titLabel.backgroundColor = [UIColor clearColor];
//    titLabel.text = @"自古英雄出少年";

    [scrollview addSubview:titLabel];
    
    audioImgV = [[UIImageView alloc]initWithFrame:CGRectMake(260, height_y(headView)+10, 27, 27)];
    audioImgV.image = [UIImage imageNamed:@"art_voice"];
//    [scrollview addSubview:audioImgV];
    audioLb = [[UILabel alloc]initWithFrame:CGRectMake(245, height_y(audioImgV), 60, 20)];
    audioLb.backgroundColor = [UIColor clearColor];
    audioLb.text = @"艺术家录音";
    audioLb.font = [UIFont systemFontOfSize:11];
    audioLb.textColor = TEXTBLACKCOLORE3;
    audioLb.textAlignment = NSTextAlignmentCenter;
    
    recordBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    recordBtn.frame = CGRectMake(audioLb.frame.origin.x, audioImgV.frame.origin.y, 60, 44);
    recordBtn.backgroundColor = [UIColor clearColor];
    [recordBtn addTarget:self action:@selector(playAudioStream) forControlEvents:UIControlEventTouchUpInside];
    
//    [scrollview addSubview:audioLb];
    
    nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, height_y(audioLb)+10, 50, 18)];
    nameLabel.font = [UIFont systemFontOfSize:13.0];
    nameLabel.textColor = [UIColor grayColor];
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.text = @"刘晓东";
    
    UIImageView *nameArrowIV = [[UIImageView alloc]initWithFrame:CGRectMake(width_x(nameLabel), nameLabel.frame.origin.y+3, 9, 11)];
    nameArrowIV.image = [UIImage imageNamed:@"launh_sure"];
    UIButton *nameBtn = [UIButton   buttonWithType:UIButtonTypeCustom];
    nameBtn.backgroundColor = [UIColor clearColor];
//    [nameLabel bringSubviewToFront:nameBtn];
    nameBtn.frame = CGRectMake(nameLabel.frame.origin.x, nameLabel.frame.origin.y, 70, 18);
    
    [nameBtn addTarget:self action:@selector(nameBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [scrollview addSubview:nameArrowIV];
    [scrollview addSubview:nameLabel];
    [scrollview addSubview:nameBtn];
    
    buMianLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, nameLabel.frame.size.height+nameLabel.frame.origin.y+10, 100, 16)];
    buMianLabel.font = [UIFont systemFontOfSize:13.0];
    buMianLabel.backgroundColor = [UIColor clearColor];
    buMianLabel.textColor = [UIColor grayColor];
    buMianLabel.text = @"布面油画 2011";
    [scrollview addSubview:buMianLabel];
    
    
    sizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, buMianLabel.frame.size.height+buMianLabel.frame.origin.y+10, 180, 16)];
    sizeLabel.font = [UIFont systemFontOfSize:13.0];
    sizeLabel.backgroundColor = [UIColor clearColor];
    sizeLabel.textColor = [UIColor grayColor];
    sizeLabel.text =@"15.2*22.9cm";
    [scrollview addSubview:sizeLabel];
    
    kjLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, sizeLabel.frame.size.height+sizeLabel.frame.origin.y+10, 100, 16)];
    kjLabel.font = [UIFont systemFontOfSize:13.0];
    kjLabel.backgroundColor = [UIColor clearColor];
    kjLabel.textColor = [UIColor grayColor];
    kjLabel.text = @"当代艺术空间";//signGallery;//
    [scrollview addSubview:kjLabel];
    
    priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, kjLabel.frame.size.height+kjLabel.frame.origin.y+10, 170, 16)];
    priceLabel.font = [UIFont systemFontOfSize:13.0];
    priceLabel.textColor = [UIColor grayColor];
    priceLabel.backgroundColor = [UIColor clearColor];
    priceLabel.text = @"45.000元 （嘉德数据2012）";//recentlySales;//
    [scrollview addSubview:priceLabel];
    
    
    wordsLabel = [[UILabel alloc] initWithFrame:CGRectMake(width_x(priceLabel)+40, priceLabel.frame.origin.y, 60, 18)];
    wordsLabel.font = [UIFont systemFontOfSize:13.0];
    wordsLabel.textColor = [UIColor grayColor];
    wordsLabel.backgroundColor = [UIColor clearColor];
    wordsLabel.text = @"文字介绍";
    
    wordsArrowIV = [[UIImageView alloc]init ];//WithFrame:CGRectMake(width_x(wordsLabel), wordsLabel.frame.origin.y+3, 9, 11)];
    wordsArrowIV.frame =CGRectMake(width_x(wordsLabel), wordsLabel.frame.origin.y+3, 9, 11);

    wordsArrowIV.image = [UIImage imageNamed:@"launh_sure"];
    UIButton *wordsBtn = [UIButton   buttonWithType:UIButtonTypeCustom];
    wordsBtn.backgroundColor = [UIColor clearColor];
    //    [nameLabel bringSubviewToFront:nameBtn];
    wordsBtn.frame = CGRectMake(wordsLabel.frame.origin.x, wordsLabel.frame.origin.y, 70, 18);
    
    [wordsBtn addTarget:self action:@selector(wordsBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [scrollview addSubview:wordsArrowIV];
    [scrollview addSubview:wordsLabel];
    [scrollview addSubview:wordsBtn];
    
     // 隐藏label
    hideLine = [[UIView alloc]initWithFrame:CGRectMake(0, height_y(wordsBtn)+10, UI_SCREEN_WIDTH, 1)];
    hideLine.backgroundColor = RGBA(219, 219, 219, 1);
    hideLine.hidden = isHideLine;
    
    introLabel = [[UILabel alloc]initWithFrame:CGRectMake(15,height_y(hideLine)+10, 290, 0)];
    introLabel.font = [UIFont systemFontOfSize:14];
    introLabel.textColor = TEXTBLACKCOLORE3;
    introLabel.backgroundColor = [UIColor clearColor];
    introLabel.text = @"文字介绍的内容";
    
    [scrollview addSubview:hideLine];
    [scrollview addSubview:introLabel];
    
    
    lineView = [[UIView alloc] initWithFrame:CGRectMake(0, height_y(introLabel), UI_SCREEN_WIDTH, 1)];
    lineView.backgroundColor = RGBA(219, 219, 219, 1);
    [scrollview addSubview:lineView];
    
    favBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    favBtn.frame = CGRectMake(0, height_y(lineView), UI_SCREEN_WIDTH/2-3, 44);
    favBtn.backgroundColor = [UIColor clearColor];
    [scrollview addSubview:favBtn];
    
    hlineView = [[UIView alloc]initWithFrame:CGRectMake(width_x(favBtn), height_y(lineView)+5, 1, 34)];
    hlineView.backgroundColor = RGBA(219, 219, 219, 1);
    [scrollview addSubview:hlineView];
    
    favIV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"artist_Fav"]];
    favIV.frame = CGRectMake(UI_SCREEN_WIDTH/4-9, 4, 18, 18);
    
    favLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 22, UI_SCREEN_WIDTH/2, 22)];
    favLabel.backgroundColor = [UIColor clearColor];
    favLabel.textColor  = TEXTBLACKCOLORE3;
    favLabel.font = [UIFont systemFontOfSize:12];
    favLabel.text = [NSString stringWithFormat:@"31次关注"];
    favLabel.textAlignment = NSTextAlignmentCenter;
    [favBtn addTarget:self action:@selector(favBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [favBtn addSubview:favLabel];
    [favBtn addSubview:favIV];
    
   
    scanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    scanBtn.frame = CGRectMake(width_x(hlineView), height_y(lineView), UI_SCREEN_WIDTH/2-3, 44);
    scanBtn.backgroundColor = [UIColor clearColor];
//    [scrollview addSubview:scanBtn];

    UIImageView * scanIV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"artist_Attention"]];
    scanIV.frame = CGRectMake(UI_SCREEN_WIDTH/4-13, 5.5, 26, 15);
    
    scanLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 22, UI_SCREEN_WIDTH/2, 22)];
    scanLabel.backgroundColor = [UIColor clearColor];
    scanLabel.textColor  = TEXTBLACKCOLORE3;
    scanLabel.font = [UIFont systemFontOfSize:12];
    scanLabel.text = [NSString stringWithFormat:@"120次浏览"];

    scanLabel.textAlignment = NSTextAlignmentCenter;
    
//    [scanBtn addSubview:scanIV];
//    [scanBtn addSubview:scanLabel];
    
    hlineView2 = [[UIView alloc] initWithFrame:CGRectMake(width_x(scanBtn), height_y(lineView)+5, 1, 34)];
    hlineView2.backgroundColor = RGBA(219, 219, 219, 1);
//    [scrollview addSubview:hlineView2];

   
    shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    shareBtn.frame = CGRectMake(width_x(hlineView), scanBtn.frame.origin.y, UI_SCREEN_WIDTH/2, 44);

//    UIImageView *shareIV = [[UIImageView alloc]initWithFrame:CGRectMake(UI_SCREEN_WIDTH/4-11, 11, 22, 22)];
//    shareIV.image = [UIImage imageNamed:@"share_icon@2x"];


    UIImageView *shareIV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"share_icon"]];
    shareIV.frame = CGRectMake(UI_SCREEN_WIDTH/4-9, 7, 18, 16);

    UILabel *shareLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 22, UI_SCREEN_WIDTH/2, 22)];
    shareLabel.backgroundColor = [UIColor clearColor];
    shareLabel.textColor  = TEXTBLACKCOLORE3;
    shareLabel.font = [UIFont systemFontOfSize:11];
    shareLabel.text = [NSString stringWithFormat:@"分享"];
    shareLabel.textAlignment = NSTextAlignmentCenter;

    [shareBtn addSubview:shareLabel];

    [shareBtn addSubview:shareIV];
    [shareBtn addTarget:self action:@selector(shareBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [scrollview addSubview:shareBtn];

    lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, height_y(shareBtn), UI_SCREEN_WIDTH, 1)];
    lineView2.backgroundColor = RGBA(219, 219, 219, 1);
    [scrollview addSubview:lineView2];
    
    tipsLb = [[UILabel  alloc]initWithFrame:CGRectMake(15, height_y(lineView2)+10, 180, 30)];
    tipsLb.text = [NSString stringWithFormat:@"这张画已经被说了0次"];
    tipsLb.backgroundColor = [UIColor clearColor];
    tipsLb.font = [UIFont systemFontOfSize:14.0];
    [scrollview addSubview:tipsLb];
    
    
    commIV = [[UIImageView alloc]initWithFrame:CGRectMake(width_x(tipsLb)+20, tipsLb.frame.origin.y+6, 18, 18)];
    commIV.image = [UIImage imageNamed:@"comment_write"];
    
    commLb = [[UILabel alloc] initWithFrame:CGRectMake(width_x(commIV)+10, commIV.frame.origin.y-6, 70, 30)];
    commLb.font = [UIFont systemFontOfSize:14];
    commLb.textColor = [UIColor blackColor];
    commLb.backgroundColor = [UIColor clearColor];
    commLb.text = @"写评论…";

    toCommitCommBtn = [UIButton   buttonWithType:UIButtonTypeCustom];
    toCommitCommBtn.backgroundColor = [UIColor clearColor];
    //    [nameLabel bringSubviewToFront:nameBtn];
    toCommitCommBtn.frame = CGRectMake(commIV.frame.origin.x, commIV.frame.origin.y, 70, 30);
    
    [toCommitCommBtn addTarget:self action:@selector(gotoComment:) forControlEvents:UIControlEventTouchUpInside];
    
    [scrollview addSubview:commIV];
    [scrollview addSubview:commLb];
    [scrollview addSubview:toCommitCommBtn];
    
    self.detailActTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,height_y(tipsLb)+5, UI_SCREEN_WIDTH,dHeightCell*commentList.count) style:UITableViewStylePlain];
    _detailActTableView.delegate = self;
    _detailActTableView.dataSource = self;
    _detailActTableView.backgroundColor = [UIColor clearColor];
    [scrollview addSubview:_detailActTableView];
    
    float height_Size = height_y(self.detailActTableView);
    
    scrollview.contentSize = CGSizeMake(320, height_Size);

    self.shareView = [[XDShareView alloc] initWithFrame:CGRectMake(0, UI_STATUS_BAR_HEIGHT, UI_SCREEN_WIDTH, UI_SCREEN_HEIGHT)];
    _shareView.delegate = self;
    _shareView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_shareView];
    _shareView.hidden =YES;
}

- (void)nameBtnClicked:(id)sender
{
    DDLOG(@"name Btn Clicked");
    DetailforArtistVC *artVC = [[DetailforArtistVC alloc]init];
    artVC.typeStr = @"1";
    artVC.idStr =artistId;
    [self.navigationController pushViewController:artVC animated:YES];
}

- (void)wordsBtnClicked:(id)sender
{
    DDLOG(@"文字介绍");
    isHideLine = !isHideLine;

    DDLOG(@"workDescription= %@",workDescription);

    if ([workDescription isKindOfClass:[NSNull class]]||[workDescription isEqualToString:@""]) {

//        introLabel.text = workDescription;// 文字描述
        [XDTools showTips:@"暂无内容" toView:self.contentView];
        return;
    }

    if (!isHideLine) {

        wordsArrowIV.frame =CGRectMake(width_x(wordsLabel), wordsLabel.frame.origin.y+3, 11, 9);
        wordsArrowIV.image = [UIImage imageNamed:@"xiajian"];

        CGSize wordSize = CGSizeMake(290, 0);
        CGRect textFram = [XDTools xyAutoSizeOfWidget:introLabel andSize:wordSize andtextFont:14];
        [introLabel setFrame:textFram];
    }else{

        wordsArrowIV.frame =CGRectMake(width_x(wordsLabel), wordsLabel.frame.origin.y+3, 9, 11);
        wordsArrowIV.image = [UIImage imageNamed:@"launh_sure"];
        [introLabel setFrame:CGRectMake(15,height_y(hideLine)+10, 290, 0)];
//        CGSize wordSize = CGSizeMake(0, 0);
//        CGRect textFram = [XDTools xyAutoSizeOfWidget:introLabel andSize:wordSize andtextFont:13.5];
//        [introLabel setFrame:textFram];
    }
    
    hideLine.hidden = isHideLine;
    [lineView setFrame:CGRectMake(0, height_y(introLabel)+5, UI_SCREEN_WIDTH, 1)];
    [favBtn setFrame:CGRectMake(0, height_y(lineView), UI_SCREEN_WIDTH/2-3, 44)] ;
    [hlineView setFrame:CGRectMake(width_x(favBtn), height_y(lineView)+5, 1, 34)];
    
    scanBtn.frame = CGRectMake(width_x(hlineView), height_y(lineView), UI_SCREEN_WIDTH/2-3, 44);
    [hlineView2 setFrame:CGRectMake(width_x(scanBtn), height_y(lineView)+5, 1, 34)];
    
    shareBtn.frame = CGRectMake(width_x(hlineView), scanBtn.frame.origin.y, UI_SCREEN_WIDTH/2, 44);
    
    [lineView2 setFrame: CGRectMake(0, height_y(shareBtn), UI_SCREEN_WIDTH, 1)];
    [tipsLb setFrame:CGRectMake(15, height_y(lineView2)+10, 180, 30)];
    [commIV setFrame:CGRectMake(width_x(tipsLb)+20, tipsLb.frame.origin.y+6, 18, 18)];
    [commLb setFrame:CGRectMake(width_x(commIV)+10, commIV.frame.origin.y-6, 70, 30)];
    [toCommitCommBtn setFrame:CGRectMake(commIV.frame.origin.x, commIV.frame.origin.y, 70, 30)];
    
    [self.detailActTableView setFrame:CGRectMake(0,height_y(tipsLb)+5, UI_SCREEN_WIDTH,dHeightCell*commentList.count)];
//    float  =
    
    float height_Size = height_y(self.detailActTableView);
   
    
    scrollview.contentSize = CGSizeMake(320, height_Size);
//    UIView * lineView
//    UIView *hlineView
//    UIImageView * favIV
//    UIView * hlineView2
//    UIView * lineView2
//    UIImageView *commIV
//    UILabel *commLb
//    UIButton *toCommitCommBtn
}


- (void)gotoComment:(id)sender
{
   
    NSUserDefaults *Defaults = [NSUserDefaults standardUserDefaults];
    UID_STR = [NSString stringWithFormat:@"%@",[Defaults valueForKey:kMY_USER_ID]];
    
    if (UID_STR == nil||[UID_STR isEqualToString:@""]||[UID_STR isKindOfClass:[NSNull class]]||[UID_STR isEqualToString:@"(null)"]){
        LoginViewController * loginView = [[LoginViewController alloc] init];
        [self.navigationController pushViewController:loginView animated:YES];
        //        [self confirmSelectTabBar:_beforeIndex];
    }else{
        CommentViewController *cv = [[CommentViewController alloc]init];
        cv.navTitle = workName;
        cv.workID = workID;
        cv.mVC = self;
        [self.navigationController pushViewController:cv animated:YES];
    }
    
}

#pragma mark  --------------tableView delegate----------------

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return commentList.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return dHeightForHeader;
}

//-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    //    NSArray * array;
//    CGFloat headerHeight=0;
//    if (tableView == _detailActTableView){
//        
//        //        array=@[@"2014年2月22日 星期一",@"2012年2月24日 星期三"];
//        headerHeight = dHeightForHeader;
//    }
//    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, headerHeight)];
//    view.backgroundColor = RGBA(217, 217, 217, 1);
//    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, UI_SCREEN_WIDTH-15, headerHeight)];
//    label.textColor = TEXTBLACKCOLORE;
//    label.font = [UIFont systemFontOfSize:15];
//    label.backgroundColor = [UIColor clearColor];
//    //    label.text = [array objectAtIndex:section];
//    //    label.text = activityDate;
//    
//    [view addSubview:label];
//    return view;
//    
//}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return dHeightCell;
}


-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    if(tableView == _detailActTableView){
        static NSString * cellName = @"cell111";
        CommentCell * cell111 = [tableView dequeueReusableCellWithIdentifier:cellName];
        if (cell111 == nil){
            cell111 = [[CommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
            cell111.backgroundColor = [UIColor clearColor];
            
        }
   
    //        imgV.backgroundColor = [UIColor greenColor];
   
        //        comLb.textAlignment = NSTextAlignmentCenter;
    
        cell111.comLb.text = [[commentList objectAtIndex:indexPath.row]valueForKey:@"commentContent"];
    NSString *timeStr = [[commentList objectAtIndex:indexPath.row]valueForKey:@"commentTime"];
    timeStr = [timeStr substringToIndex:16];
        cell111.tcomLb.text = timeStr;


    
        return cell111;
//    }
//    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
   
    
}
- (void)favBtnClicked:(id)sender
{
    DDLOG(@"关注按钮点击");
    NSUserDefaults *Defaults = [NSUserDefaults standardUserDefaults];
    UID_STR = [NSString stringWithFormat:@"%@",[Defaults valueForKey:kMY_USER_ID]];

    if (UID_STR == nil||[UID_STR isEqualToString:@""]||[UID_STR isKindOfClass:[NSNull class]]||[UID_STR isEqualToString:@"(null)"]){
        LoginViewController * loginView = [[LoginViewController alloc] init];
        [self.navigationController pushViewController:loginView animated:YES];
//        [self confirmSelectTabBar:_beforeIndex];
    }else{
//        [self isFavorite];
        if (isFav) {
            favIV.image = [UIImage imageNamed:@"artist_NFav"];
            [self cancelFavorite];//取消
        }else{
            favIV.image = [UIImage imageNamed:@"artist_Fav"];
            [self addFavorite];// 添加
        }
        
        isFav = !isFav;

    }

    
}
//分享
-(void)shareBtnClick
{

    DDLOG_CURRENT_METHOD;
//    [UMSocialSnsService presentSnsIconSheetView:self
//                                         appKey:UMAPPKEY
//                                      shareText:SHARETITLE
//                                     shareImage:[UIImage imageNamed:@"Icon"]
//                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToWechatSession,UMShareToWechatTimeline,nil]
//                                       delegate:nil];
    
    _shareView.hidden =NO;
 
}

#pragma mark ================XDShareView Delegate===============
-(void)shareViewBtnCLick:(UIButton *)button
{
    int tag = button.tag - SHAREBTNTAG;
    //设置分享内容和回调对象
    if (tag == 0){
        //微信会话
        [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeText;
        [[UMSocialControllerService defaultControllerService] setShareText:@"分享到微信－找画APP" shareImage:[UIImage imageNamed:@"Icon"] socialUIDelegate:self];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
    }else if (tag == 1){
        //朋友圈分享
        [[UMSocialControllerService defaultControllerService] setShareText:@"分享到朋友圈－找画APP" shareImage:[UIImage imageNamed:@"Icon"] socialUIDelegate:self];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
    }else if (tag == 2){
        //新浪微博
        [[UMSocialControllerService defaultControllerService] setShareText:@"分享到新浪微博－找画APP" shareImage:[UIImage imageNamed:@"Icon"] socialUIDelegate:self];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
    }else if (tag == 3){
        //复制链接地址
        [[UIPasteboard generalPasteboard] setString:[NSString stringWithFormat:@"%@%@",ImageMainUrl,workBigImageUrl]];
        [XDTools showTips:@"复制成功" toView:_shareView];
    }else if (tag == 4){
        //关闭
        _shareView.hidden =YES;
    }
}

-(void)rightBtnClick
{
    [popupview GetStarWorkPVInfoById:self.workID];
    
    [popupview setpopupviewshow:YES];
}

// 手势方法
-(void)whenClickImage

{
    NSArray* url = [NSArray arrayWithObjects:workBigImageUrl, nil];
    
    DDLOG(@"you click image");
    MU_bigImagesViewController* imageviewcontroller=[[MU_bigImagesViewController alloc] init];
//    imageviewcontroller.startIndex = index;
    imageviewcontroller.urlArr = url;
    imageviewcontroller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;//交叉融入
    SETSTATUSBARHIDDEN(YES);
    
    [self presentViewController:imageviewcontroller animated:YES completion:nil];
    
}

- (void)playAudioStream
{
    DDLOG(@"播放录音");
}
#pragma mark  -------- DataSouceManager------------

- (void)getArtistRecord
{
    DDLOG(@"workID = %@  uid = %@ ",self.workID,UID_STR);
    
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <getArtistRecord xmlns=\"http://tempuri.org/\">"
                          "<workId>%@</workId>"
                          "</getArtistRecord>",self.workID];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:GETARTISTRECORD];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                    
                    recordURL = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"hasStore"]];
                    DDLOG(@"recordURL = %@",recordURL);
                    
                    if (recordURL ==nil ||![recordURL isKindOfClass:[NSNull class]]||[recordURL isEqualToString:@"<null>"]) {
//                        [self addFavorite];// 不显示
                        
                    }else{
                        [scrollview addSubview:audioImgV];
                        [scrollview addSubview:audioLb];
                        [scrollview addSubview:recordBtn];
                        
//                        [self cancelFavorite];//取消
                    }
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }

}
- (void)getXmlData
{
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <WorkDetailByWorkId xmlns=\"http://tempuri.org/\">"
                          "<workId>%@</workId>"
                          "</WorkDetailByWorkId>",self.workID];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:WORKDETAILBYWORK];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                    
                    author = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"author"]];
                    beScanTime = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"beScanTime"]];
                    beStoreTime = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"beStoreTime"]];
                    workCategory = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"workCategory"]];
                    workDate = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"workDate"]];
                    workName = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"workName"]];
                    [commentList removeAllObjects];
                    
                    NSArray *ar = [responseDict valueForKey:@"commentList"];
                    [commentList addObjectsFromArray:ar];
                    workSize = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"workSize"]];
                    beCommentTime = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"beCommentTime"]];
                    artistId = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"artistId"]];
                    
                    recentlySales = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"recentlySales"]];
                    signGallery = [responseDict valueForKey:@"signGallery"];
                    workBigImageUrl = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"workBigImageUrl"]];
                    workDescription = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"workDescription"]];
                    workSmallImageUrl = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"workSmallImageUrl"]];
                    
                    NSString * imageUrl = [NSString stringWithFormat:@"%@%@",ImageMainUrl,workSmallImageUrl];
                    NSString * urlstring = [imageUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                    headView.tag = 200;
                    [headView setImageWithURL:[NSURL URLWithString:urlstring]];
//                    [self initViews];
                    if (![author isKindOfClass:[NSNull class]]&&![author isEqualToString:@"<null>"]) {
                        
                        nameLabel.text = author;
                    }
                    if (![workName isKindOfClass:[NSNull class]]&&![workName isEqualToString:@"<null>"]) {
                       
                        titLabel.text = workName;//
                    }else{
                        titLabel.text = @"";
                    }
                    
                    
                    if (![workCategory isKindOfClass:[NSNull class]]&&![workDate isKindOfClass:[NSNull class]]&&![workCategory isEqualToString:@"<null>"]&&![workDate isEqualToString:@"<null>"]) {
                        
                        buMianLabel.text = [NSString stringWithFormat:@"%@ %@",workCategory,workDate];
                    }
                    if (![workSize isKindOfClass:[NSNull class]]&&![workSize isEqualToString:@"<null>"]) {
                       
                        sizeLabel.text = workSize;
                    }
                    
                    if (![signGallery isKindOfClass:[NSNull class]]&&![signGallery isEqualToString:@"<null>"]) {
                        kjLabel.text = signGallery;//
                    }
                    
                    if (![recentlySales isKindOfClass:[NSNull class]]&&![recentlySales isEqualToString:@"<null>"]) {
                       priceLabel.text = recentlySales;//
                    }
                    
                    if (![workDescription isKindOfClass:[NSNull class]]&&![workDescription isEqualToString:@"<null>"]) {
                        
                        introLabel.text = workDescription;// 文字描述
                    }
                    
                    if (![beStoreTime isKindOfClass:[NSNull class]]&&![beStoreTime isEqualToString:@"<null>"]) {
                       favLabel.text = [NSString stringWithFormat:@"%@次关注",beStoreTime];
                    }
                    
                    if (![beScanTime isKindOfClass:[NSNull class]]&&![beScanTime isEqualToString:@"<null>"]) {
                       scanLabel.text = [NSString stringWithFormat:@"%@次浏览",beScanTime];
                    }
                    beCommentTime = [NSString stringWithFormat:@"%d",[commentList count]];
                    if (![beCommentTime isKindOfClass:[NSNull class]]&&![beCommentTime isEqualToString:@"<null>"]) {
                        
                        tipsLb.text = [NSString stringWithFormat:@"这张画已经被说了%@次",beCommentTime];
//                        [tipsLb sizeToFit];
                    }
                    
                    [self.detailActTableView setFrame:CGRectMake(0,height_y(tipsLb)+5, UI_SCREEN_WIDTH,dHeightCell*commentList.count)];
//
                    float height_Size = height_y(self.detailActTableView);
//
                    scrollview.contentSize = CGSizeMake(320, height_Size);
                    
//                    [self initViews];

                    [_detailActTableView reloadData];
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
    
}


#pragma mark -- -------picblock delegate--------------

-(void)onClick:(MU_picBlock *)block
{
    int index = block.mu_index;
    //NSLog(@"click == %i",index);
    
    //获取链接数组
    NSMutableArray* urlArr = [[NSMutableArray alloc] initWithCapacity:0];
//    for (NSDictionary* dic in _dataArr)
//    {
//        NSString* url = [dic valueForKey:@"picUrl"];
//        [urlArr addObject:url];
//    }
    
    MU_bigImagesViewController* imageviewcontroller=[[MU_bigImagesViewController alloc] init];
    imageviewcontroller.startIndex = index;
    imageviewcontroller.urlArr = urlArr;
    imageviewcontroller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;//交叉融入
    [self presentViewController:imageviewcontroller animated:YES completion:nil];//:imageviewcontroller animated:YES];
}
//、、判断是否已经收藏
- (void)isFavorite{

    UID_STR = [[NSUserDefaults standardUserDefaults] valueForKey:kMY_USER_ID];
    
    DDLOG(@"workID = %@  uid = %@ ",self.workID,UID_STR);
    
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <GetMyStoreInfor xmlns=\"http://tempuri.org/\">"
                          "<id>%@</id>"
                          "<uid>%@</uid>"
                          "<type>%@</type>"
                          "</GetMyStoreInfor>",self.workID,UID_STR,@"0"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:GetMyStoreInfor];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                    
                    isFav = [[NSString stringWithFormat:@"%@",[responseDict valueForKey:@"hasStore"]]boolValue];
                    DDLOG(@"ISFAV = %d",isFav);
                    
                    
                    if (isFav) {
                        favIV.image = [UIImage imageNamed:@"artist_Fav"];
                        
                    }else{
                        favIV.image = [UIImage imageNamed:@"artist_NFav"];
                        
                    }
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }


}
// 添加收藏

- (void)addFavorite{

    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <AddStore xmlns=\"http://tempuri.org/\">"
                          "<id>%@</id>"
                          "<uid>%@</uid>"
                          "<type>%@</type>"
                          "</AddStore>",self.workID,UID_STR,@"0"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:addStore];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                   
                    beStoreTime = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"totalStore"]];
                    if ([beStoreTime isKindOfClass:[NSNull class]]&&[beStoreTime isEqualToString:@"<null>"]) {
                        beStoreTime = @"0";
                    }
                    favLabel.text = [NSString stringWithFormat:@"%@次关注",beStoreTime];
                    [XDTools showTips:@"添加关注成功" toView:self.contentView];
                    favIV.image = [UIImage imageNamed:@"artist_Fav"];
                }else{
                    [XDTools showTips:@"添加关注失败" toView:self.contentView];
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }

}
// 取消收藏
- (void)cancelFavorite
{
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <CancelStore xmlns=\"http://tempuri.org/\">"
                          "<id>%@</id>"
                          "<uid>%@</uid>"
                          "<type>%@</type>"
                          "</CancelStore>",self.workID,UID_STR,@"0"];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:cancelStore];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                    
                    beStoreTime = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"totalStore"]];
                    if ([beStoreTime isKindOfClass:[NSNull class]]&&[beStoreTime isEqualToString:@"<null>"]) {
                        beStoreTime = @"0";
                    }
                    favLabel.text = [NSString stringWithFormat:@"%@次关注",beStoreTime];
                    [XDTools showTips:@"取消关注成功" toView:self.contentView];
                    favIV.image = [UIImage imageNamed:@"artist_NFav"];

                }else{
                  [XDTools showTips:@"取消关注失败 " toView:self.contentView];
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
